package com.example.dataservice.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.api.model.FinanceAccount;

import java.math.BigDecimal;

public interface FinanceAccountMapper {

    @Select("""
            select * 
            from u_finance_account 
            where uid = #{uid}
            for update
            """)
    /*根据用户id查询*/
    FinanceAccount selectByUserId(Integer uid);

    int deleteByPrimaryKey(Integer id);

    int insert(FinanceAccount record);

    int insertSelective(FinanceAccount record);

    FinanceAccount selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(FinanceAccount record);

    int updateByPrimaryKey(FinanceAccount record);

    @Update("""
            update u_finance_account
            set available_money = available_money + #{availableMoney}
            where uid = #{uid}
            """)
    /*收益返还，更新账户资金*/
    int updateAvailableByIncomeBack(FinanceAccount account);


    @Update("""
            update u_finance_account
            set available_money = available_money + #{rechargeMoney}
            where uid = #{uid}
            """)
    /*更新用户账户余额*/
    int updateAccountAvailableMoney(@Param("uid") Integer uid, @Param("rechargeMoney") BigDecimal rechargeMoney);
}